<template>

    <h2>添加信息</h2>

    <table class="table table-bordered">
            <tr>
                    <th>卷类型</th>
                    <th>
                            <select v-model="Tianjia1.juanType">
                                    <option value="卷类型">卷类型</option>
                                    <option value="代金卷">代金卷</option>
                                    <option value="补偿卷">补偿卷</option>
                            </select>
                    </th>

            </tr>


            <tr>
                    <th>代金卷标题</th>
                    <th>
                            <input type="text" v-model="Tianjia1.mname">
                    </th>

            </tr>


            <tr>
                    <th>代金卷副标题</th>
                    <th>
                            <input type="text" v-model="Tianjia1.mtname">
                    </th>

            </tr>


            <tr>
                    <th>代金卷图片</th>
                    <th>
                            <img :src="Tianjia1.mimg" style="width: 80px; height:100px;">
                            <input type="file" @change="Upfile">
                    </th>

            </tr>


            <tr>
                    <th>剩余库存</th>
                    <th>
                            <input type="text" v-model="Tianjia1.mnum">
                    </th>

            </tr>




            <tr>
                    <th>使用条件</th>
                    <th>
                            <input type="text" v-model="Tianjia1.tiaoJian">
                    </th>

            </tr>


            <tr>
                    <th>减免金额</th>
                    <th>
                            <input type="text" v-model="Tianjia1.jianMian">
                    </th>

            </tr>


            <tr>
                    <th>有效期</th>
                    <th>
                            <input type="date" v-model="Tianjia1.ctime">
                            <input type="date" v-model="Tianjia1.stime">
                    </th>

            </tr>


            <tr>
                    <th>适用业务</th>
                    <th>
                            <input type="checkbox" value="订房" :checked="XuanZe" v-model="DuoXuan"> 订房
                            <input type="checkbox" value="商城" :checked="XuanZe" v-model="DuoXuan"> 商城
                            <input type="checkbox" value="堂食" :checked="XuanZe" v-model="DuoXuan"> 堂食
                            <input type="checkbox" value="收款码" :checked="XuanZe" v-model="DuoXuan"> 收款码
                    </th>

            </tr>


            <tr>
                    <th>使用须知</th>
                    <th>
                            <textarea v-model="Tianjia1.xuZhi"></textarea>
                    </th>

            </tr>



            <tr>
                    <th>适用门店</th>
                    <th>
                            <select v-model="Tianjia1.tid">
                                    <option :value="-1">请选择</option>
                                    <option v-for="item in FanTian" :value="item.tid">{{ item.tname }}</option>
                            </select>
                    </th>

            </tr>


            <tr>
                    <th>服务电话</th>
                    <th>
                            <input type="text" v-model="Tianjia1.mPhone">
                    </th>

            </tr>

            <tr>
                    <th></th>
                    <th>
                            <button value="修改" @click="AddMe">修改</button>
                    </th>

            </tr>


    </table>



</template>

<script setup lang="ts">



const DuoXuan:any = ref([])
const XuanZe = ref(false)






import router from '@/router';
import axios from 'axios';
import { duration } from 'moment';
import { onMounted, ref } from 'vue';

const Upfile = (e: any) => {

    var a = e.target.files[0];
    var b = new FormData();
    b.append("Images", a);

    axios.post('https://localhost:7039/api/UpFile/UpFi', b).then(res => {


            Tianjia1.value.mimg = res.data





    })

}



const FanTian = ref([{

    "tid": 0,
    "tname": ""

}])


onMounted(() => {

    FanTian1();
    FanTian123();
    Split();
})


const FanTian1 = () => {


    axios.get('https://localhost:7039/api/User/ShowType').then(res => {

            FanTian.value = res.data

    })

}


import { useRoute,useRouter,createRouter } from 'vue-router';


const route=useRoute()
const Tianjia1 = ref({

    "mid": route.params.id,
    "mname": "",
    "mtname": "",
    "mimg": "",
    "mnum": 0,
    "tiaoJian": 0,
    "jianMian": 0,
    "ctime": "",
    "stime": "",
    "yeWu":"",
    "xuZhi": "",
    "juanType": "卷类型",
    "mPhone": "",
    "tid": -1,
    "isDel": true


})






const AddMe = () => {

    
    Tianjia1.value.yeWu=DuoXuan.value.toString();

    axios.put('https://localhost:7039/api/User/UpMArk', Tianjia1.value).then(res => {



            if (res.data > 0) {
                    alert('修改成功')
                    router.push('/')
            }
            else {
                    alert('修改失败')
            }
    })



}



const Split=()=>{




}





const nfa =ref('')



const FanTian123=()=>{

    axios.get('https://localhost:7039/api/User/FanTian',{params:{
        id:route.params.id
    }}).then(res=>{
       
      //  aa.value=res.data.yeWu
        //alert(aa.value.split(','))
        nfa .value=res.data.yeWu

        DuoXuan.value=nfa.value.split(',')

        Tianjia1.value=res.data
    
    

    })




}

</script>